import json

# class JsonEncoder(json.JSONEncoder):
    
def json_encoder(obj):
    if hasattr(obj, 'to_dict'):
        return obj.to_dict()
    raise TypeError(f"Object of type {type(obj).__name__} is not JSON serializable")